<?

/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) 2008-2011 JohnCMS Community
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      http://johncms.com/about
 */

defined('_IN_JOHNCMS') or die('Error: restricted access');

/*
-----------------------------------------------------------------
Блок информации
-----------------------------------------------------------------
*/
echo '<div class="phdr"><b>Блог сайта</b></div>';
$mp = new mainpage(); echo $mp->news;

/*
-----------------------------------------------------------------
Библиотека
-----------------------------------------------------------------
*/

$req = mysql_query("SELECT COUNT(*) FROM `lib` WHERE `time` > '" . (time() -
    259200) . "' AND `type` = 'bk' AND `moder` = '1'");
$total = mysql_result($req, 0);
if ($total > 0) {
    echo '<div class="phdr"><b>Новые статьи</b></div>';
    $req = mysql_query("SELECT * FROM `lib` WHERE `time` > '" . (time() - 259200) .
        "' AND `type` = 'bk' AND `moder` = '1' ORDER BY `time` DESC LIMIT " . $start .
        "," . $kmess);
    $i = 0;
    while ($newf = mysql_fetch_array($req)) {
        echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
        echo '<a href="/library/?id=' . $newf['id'] . '"><strong>' . htmlentities($newf['name'],
            ENT_QUOTES, 'UTF-8') . '</strong></a><br/>';
            
        if ($newf['announce'] != '')
            echo '<span style="font-size:13px">' . htmlentities($newf['announce'], ENT_QUOTES, 'UTF-8') . '</span><br />';
        echo '<span style="font-size:x-small">' . $lng_lib['added'] . ' ' . $newf['avtor'] . ' (' . functions::display_date($newf['time']) .
            ')</span>';
        echo '</div>';
        $i++;
        if ($i == 5) break;
    }
}

if ($is_mobile) {

    /*
    -----------------------------------------------------------------
    Блок общения
    -----------------------------------------------------------------
    */
    echo '<div class="phdr"><b>' . $lng['dialogue'] . '</b></div>';
    // Ссылка на гостевую
    if ($set['mod_guest'] || $rights >= 7)
        echo '<div class="menu"><a href="guestbook/index.php">' . $lng['guestbook'] .
            '</a> (' . counters::guestbook() . ')</div>';
    // Ссылка на Форум
    if ($set['mod_forum'] || $rights >= 7)
        echo '<div class="menu"><a href="forum/">' . $lng['forum'] . '</a> (' . counters::
            forum() . ')</div>';

    /*
    -----------------------------------------------------------------
    Блок полезного
    -----------------------------------------------------------------
    */
    echo '<div class="phdr"><b>' . $lng['useful'] . '</b></div>';
    // Ссылка на загрузки
    if ($set['mod_down'] || $rights >= 7)
        echo '<div class="menu"><a href="download/">' . $lng['downloads'] . '</a> (' .
            counters::downloads() . ')</div>';
    // Ссылка на библиотеку
    if ($set['mod_lib'] || $rights >= 7)
        echo '<div class="menu"><a href="library/">' . $lng['library'] . '</a> (' .
            counters::library() . ')</div>';
    // Ссылка на библиотеку
    if ($set['mod_gal'] || $rights >= 7)
        echo '<div class="menu"><a href="gallery/">' . $lng['gallery'] . '</a> (' .
            counters::gallery() . ')</div>';
    if ($user_id || $set['active']) {
        echo '<div class="phdr"><b>' . $lng['community'] . '</b></div>' .
            '<div class="menu"><a href="users/index.php">' . $lng['users'] . '</a> (' .
            counters::users() . ')</div>' . '<div class="menu"><a href="users/album.php">' .
            $lng['photo_albums'] . '</a> (' . counters::album() . ')</div>';
            
            
// Реклама

echo '<div class="phdr"><b>Реклама</b></div>';            
echo '<div class="smenu">';

// MobileAds
$mad_socketTimeout = 2; // таймаут соединения с сервером mobileads.ru
ini_set("default_socket_timeout",$mad_socketTimeout);
$mad_siteId = 5946;
$mad_pageEncoding = "UTF-8"; // устанавливаем кодировку страницы

$mad_ua = urlencode(@$_SERVER['HTTP_USER_AGENT']);
$mad_ip = urlencode(@$_SERVER['REMOTE_ADDR']);
$mad_xip = urlencode(@$_SERVER['HTTP_X_FORWARDED_FOR']);
$mad_ref = urlencode(@$_SERVER['SERVER_NAME'].@$_SERVER['REQUEST_URI']);

$mad_lines = "";
$mad_fp = @fsockopen ("mobileads.ru", 80, $mad_errno, $mad_errstr, $mad_socketTimeout);
if($mad_fp) {
// переменная $mad_lines будет содержать массив, непарные элементы которого будут ссылками, парные - названием
$mad_lines = @file("http://mobileads.ru/links?id=$mad_siteId&ip=$mad_ip&xip=$mad_xip&ua=$mad_ua&ref=$mad_ref");
}
@fclose($mad_fp); // вывод ссылок
for($malCount=0; $malCount < count($mad_lines); $malCount+=2){
  $linkURL = trim($mad_lines[$malCount]);
  $linkName = iconv("Windows-1251", $mad_pageEncoding, $mad_lines[$malCount+1]);
  echo "<a href=\"".$linkURL."\">".$linkName."</a><br />";
}
echo '</div>';

    }
} else {
    /*
    -----------------------------------------------------------------
    форум
    -----------------------------------------------------------------
    */

    $set_forum = $datauser['set_forum'] ? unserialize($datauser['set_forum']) :
        array();
    $settings = $set['lastThemes'] ? unserialize($set['lastThemes']) : array('totalThemes' =>
            7, 'timeCache' => 30);
    if ($settings['totalThemes'] > 0 && !$set_forum['viewThemes']) {
        $themesOut = '';
        $file_cache = 'files/cache/lastThemes.dat';
        echo '<div class="phdr"><b>Последние ответы</b></div>';
        $req = mysql_query("SELECT * FROM `forum` WHERE `type`='t'" . ($rights >= 7 ? '' :
            " AND `close`!='1'") . " ORDER BY `time` DESC LIMIT " . $settings['totalThemes']);
        while (($res = mysql_fetch_assoc($req)) !== false) {
            if ($res['close'])
                $themesOut .= '<div class="rmenu">';
            else
                $themesOut .= $i % 2 ? '<div class="list2">' : '<div class="list1">';
            $nickUser = mysql_fetch_assoc(mysql_query("SELECT `from` FROM `forum` WHERE `type` = 'm' AND `close` != '1' AND `refid` = '" .
                $res['id'] . "' ORDER BY `time` DESC LIMIT 1"));
            $totalPosts = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `refid`='" .
                $res['id'] . "'" . ($rights >= 7 ? '' : " AND `close` != '1'")), 0);
            $endPage = ceil($totalPosts / $kmess);
            $icons = array(
                (!$res['vip'] ? '<img src="../theme/' . $set_user['skin'] .
                    '/images/op.gif" alt=""/>' : ''),
                ($res['vip'] ? '<img src="../theme/' . $set_user['skin'] .
                    '/images/pt.gif" alt=""/>' : ''),
                ($res['realid'] ? '<img src="../theme/' . $set_user['skin'] .
                    '/images/rate.gif" alt=""/>' : ''),
                ($res['edit'] ? '<img src="../theme/' . $set_user['skin'] .
                    '/images/tz.gif" alt=""/>' : ''));
            $themesOut .= functions::display_menu($icons, '&#160;', '&#160;') .
                '<a href="/forum/index.php?id=' . $res['id'] . '">' . $res['text'] . '</a> [' .
                $totalPosts . ']';
            if ($endPage > 1)
                $themesOut .= '<a href="forum/index.php?id=' . $res['id'] . '&amp;page=' . $endPage .
                    '">&#160;&gt;&gt;</a>';
            $themesOut .= '<div class="sub">' . $res['from'];
            if (!empty($nickUser['from']))
                $themesOut .= '&#160;/&#160;' . $nickUser['from'];
            $themesOut .= ' <span class="gray">(' . functions::display_date($res['time']) .
                ')</span></div></div>';
            ++$i;
        }
        if ($settings['timeCache'] > 0 && time() < (filemtime($file_cache) + $settings['timeCache'])) {
            echo file_get_contents($file_cache);
        } else {
            echo $themesOut;
            if ($settings['timeCache'] > 0)
                file_put_contents($file_cache, $themesOut);
        }
    }

    /*
    -----------------------------------------------------------------
    Остальное
    -----------------------------------------------------------------
    */

    if ($user_id || $set['active']) {
        echo '<div class="phdr"><b>Наш актив</b></div>' .
            '<div class="menu"><a href="users/index.php">Юзеры</a> (' . counters::users() .
            ')</div>' . '<div class="menu"><a href="users/album.php">' . $lng['photo_albums'] .
            '</a> (' . counters::album() . ')</div>';
    }

}
?>